<?php

namespace App\Http\Requests\Backend;

use Illuminate\Foundation\Http\FormRequest;

class MemberRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|unique:users,name',
            'mobile' => 'required|unique:users,mobile',
            'email' => 'required|unique:users,email',
            'password' => 'required',
        ];
    }
    public function messages()
    {
        return [
            'name.required' => '请输入昵称',
            'name.unique' => '昵称已经存在',
            'mobile.required' => '请输入手机号',
            'mobile.unique' => '手机号已经存在',
            'email.required' => '请输入邮箱',
            'email.unique' => '邮箱已经存在',
            'password.required' => '请输入密码',
        ];
    }

    public function filldata()
    {
        return [
            'avatar' => $this->post('avatar'),
            'name' => $this->post('name'),
            'mobile' => $this->post('mobile'),
            'email' => $this->post('email'),
            'password' => bcrypt($this->post('password')),
            'is_active' => 1,
        ];
    }
}
